package com.cweb.admin.model.bbs.bbs_article_info.service;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cweb.admin.model.bbs.bbs_article_info.entity.BbsArticleInfo;
import com.cweb.admin.model.bbs.bbs_article_info.mapper.BbsArticleInfoMapper;
import com.cweb.admin.serivce.authority.UserLoginService;
import com.cweb.framework.base.serivce.BaseMybatisService;
import com.cweb.framework.pojo.BaseResponse;
import com.cweb.framework.pojo.PageParam;
import com.cweb.framework.util.MybatisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 论坛-文章信息 服务实现类
 * @since 2020-08-25
 */
@Service
public class BbsArticleInfoService extends BaseMybatisService<BbsArticleInfoMapper, BbsArticleInfo> {
    @Autowired
    private UserLoginService userLoginService;

    /**
     * 取得文章
     */
    public Object detail(Long articleId) {
        return this.getBaseMapper().detail(articleId, userLoginService.getCurLoginUserId());
    }

    /**
     * 分页查询
     */
    public Object getList(BbsArticleInfo param, PageParam pageParam) {
        return this.getBaseMapper().listPage(MybatisUtil.initCondPage(pageParam), param);
    }

    /**
     * 新建文章
     */
    public Object make(BbsArticleInfo param) {
        BbsArticleInfo bbsArticleInfo = new BbsArticleInfo();
        bbsArticleInfo.setAuthor(userLoginService.getCurLoginUserId());
        bbsArticleInfo.setTitle(param.getTitle()); // 标题
        bbsArticleInfo.setThumb(param.getThumb()); // 缩略图
        bbsArticleInfo.setCategory(param.getCategory()); // 分类
        bbsArticleInfo.setContent(param.getContent()); // 内容
        bbsArticleInfo.setVersion(1); // 版本
        return this.save(bbsArticleInfo);
    }
}
